package singleton.lazy.security.type1;

import lombok.SneakyThrows;

public class ReflectInjection {
    @SneakyThrows
    public static void main(String[] args) {
//        //获取到类定义
//        Class x = Singleton.class;
//        //获取构造器
//        Constructor constructor = x.getDeclaredConstructors()[0];
//        //设置可以访问
//        constructor.setAccessible(true);
//        Singleton o = (Singleton) constructor.newInstance();
//        //获取单例
//        Singleton instance = Singleton.getInstance();
//        //比较单例与初始化的实例
//        if (instance == o) {
//            System.out.println("相同的实例");
//        } else {
//            System.out.println("不同的实例");
//        }

        Singleton instance1 = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance1 == instance2);
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());
    }
}
